#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* read file data into buf and print the buf */

FILE *deal_file(FILE *fp, void **pbuf)
{
    if (fp) {
        char ch;
        char *p = *pbuf;

        do {
            ch = fgetc(fp);
            if (feof(fp)) {
                break;
            }
            *p = ch;
            p++;
        } while (1);
    }
    return fp;
}

void *deal_buf(void *buf)
{
    if (buf) {
        memset(buf, 0, 512);
        fclose(deal_file(fopen("hello.txt", "r"), &buf));
    }
    return buf;
}

void *print_buf(void *buf)
{
    if (buf)
        printf("buf: %s\n", buf);
    else
        printf("buf null!\n");
    return buf;
}

int main(int argc, char *argv[])
{
    free(print_buf(deal_buf(malloc(512))));

    return 0;
}
